//
//  CameraBottomView.m
//  Runner
//
//  Created by tock on 2023/9/23.
//

#import "CameraBottomView.h"

@implementation CameraBottomView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor =[UIColor blackColor];
        [self initSubViews];
    }
    return self;
}
-(void)initSubViews{
    [self addSubview:self.takeBtn];
    [self addSubview:self.cancelBtn];
    [self addSubview:self.nextBtn];
}

- (UIButton *)takeBtn{
    if (!_takeBtn) {
        _takeBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.frame.size.width/2-35, self.frame.size.height-100, 70, 70)];
        [_takeBtn setImage:[UIImage imageNamed:@"photo_camera_take"] forState:UIControlStateNormal];
        [_takeBtn addTarget:self action:@selector(takeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _takeBtn;
}


-(UIButton *)cancelBtn{
    if (!_cancelBtn) {
        _cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(50, self.frame.size.height-90, 44, 44)];
        _cancelBtn.hidden = YES;
        [_cancelBtn setImage:[UIImage imageNamed:@"photo_camera_back"] forState:UIControlStateNormal];
        [_cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelBtn;;
}

-(UIButton *)nextBtn{
    if (!_nextBtn) {
        _nextBtn = [[UIButton alloc]initWithFrame:CGRectMake(self.frame.size.width-100, self.frame.size.height-90, 44,44)];
        _nextBtn.hidden = YES;
        [_nextBtn setImage:[UIImage imageNamed:@"photo_camera_next"] forState:UIControlStateNormal];
        [_nextBtn addTarget:self action:@selector(nextBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextBtn;;
}


-(void)cancelBtnClick{

    if ([self.delegate respondsToSelector:@selector(BSVideoBottomView:didClickFuncBtnWithType:)]) {
        [self.delegate BSVideoBottomView:self didClickFuncBtnWithType:FUNC_TYPE_RETRY];
        [self refreshUIHiddenStatusIsHidden:NO];
    }
}

-(void)nextBtnClick{
    if ([self.delegate respondsToSelector:@selector(BSVideoBottomView:didClickFuncBtnWithType:)]) {
        [self.delegate BSVideoBottomView:self didClickFuncBtnWithType:FUNC_TYPE_NEXT];
    }
}


-(void)takeBtnClick{
    
    self.takeBtn.selected = !self.takeBtn.selected;
    if ([self.delegate respondsToSelector:@selector(BSVideoBottomView:didClickFuncBtnWithType:)]) {
        [self.delegate BSVideoBottomView:self didClickFuncBtnWithType:FUNC_TYPE_PIC];
        [self refreshUIHiddenStatusIsHidden:YES];
    }
}


-(void)refreshUIHiddenStatusIsHidden:(BOOL)hidden{
    self.nextBtn.hidden = !hidden;
    self.takeBtn.hidden = hidden;
    self.cancelBtn.hidden = !hidden;
}

@end
